package com.huike.controller.business;

import com.huike.dto.*;
import com.huike.entity.CustomerInfo;
import com.huike.entity.DeptCustomer;
import com.huike.result.PageResult;
import com.huike.result.Result;
import com.huike.service.BusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/users/business")
public class BusinessController {

    @Autowired
    private BusinessService businessService;

    /**
     * 商机分页查询
     *
     * @param businessPageDto
     * @return
     */
    @GetMapping("/page")
    public Result findPage(BusinessPageDto businessPageDto) {

        PageResult pageResult = businessService.findPage(businessPageDto);

        return Result.success(pageResult);
    }

    /**
     * 查询归属人
     *
     * @return
     */
    @GetMapping("/findBelonger")
    public Result findBelonger() {
        List<String> list = businessService.findBelonger();
        Map map = new HashMap<>();
        map.put("belonger", list);
        return Result.success(map);
    }

    /**
     * 查询商机状态
     */
    @GetMapping("/clue_status")
    public Result findStatus() {
        List<String> list = businessService.findStatus();
        Map map = new HashMap();
        map.put("status", list);
        return Result.success(map);
    }

    /**
     * 新建商机
     *
     * @param newCustomerDto
     * @return
     */
    @PostMapping
    public Result save(@RequestBody NewCustomerDto newCustomerDto) {
        businessService.save(newCustomerDto);
        return Result.success("新建成功");
    }

    /**
     * 渠道查询
     */
    @GetMapping("/clues_item")
    public Result findItem() {
        List<String> list = businessService.findItem();
        Map map = new HashMap();
        map.put("item", list);
        return Result.success(list);
    }

    /**
     * 查询退回公海池理由
     */
    @GetMapping("/sea/reason")
    public Result findReason() {
        return businessService.findReason();
    }

    /**
     * 退回公海池
     *
     * @param dto
     * @return
     */
    @PostMapping("/toSea")
    public Result toSea(@RequestBody BusinessToSeaDto dto) {
        return businessService.toSea(dto);
    }

    /**
     * 查询所有下拉框
     *
     * @return
     */
    @GetMapping("/allDictData")
    public Result findAllDictData() {
        return businessService.findAllDictData();
    }

    /**
     * 分配线索部门回显
     */
    @GetMapping("/dept")
    public Result findAllDept() {
        return businessService.findAllDept();
    }

    /**
     * 线索分配
     */
    @PostMapping("/cueAllocation")
    public Result cueAllocation(@RequestBody DeptCustomerDto dto) {
        return businessService.cueAllocation(dto);
    }



    /**
     * id查询客户资料
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable Long id) {
        return businessService.getById(id);
    }

    /**
     * 添加沟通记录
     *
     * @param customerInfo
     * @return
     */
    @PostMapping("/addRecord")
    public Result addRecord(@RequestBody CustomerInfoDto customerInfo) {
        return businessService.addRecord(customerInfo);
    }

    /**
     * 查询历史沟通记录
     * @param customerId
     * @return
     */
    @GetMapping("/searchHistory")
    public Result searchHistory(Long customerId) {
        return businessService.searchHistory(customerId);
    }
}
